package com.lottery.utils.playUtils;


import sun.nio.cs.FastCharsetProvider;

import java.util.*;

public class SscPlayUtilsNoNum {
    private boolean flag = false;
    private Map<String, List<Integer>> opencodeMap;

    private String opencode;

    private List<String> sscShunzi;//ssc顺子的可能中奖的集合{前,中},如果没有则为空需做null处理

    private List<String> sscBaozi;//ssc豹子可能中奖的集合,同上

    private List<String> sscDuizi;//ssc对子可能中奖的集合,同上

    private List<String> sscBanShun;//ssc

    public SscPlayUtilsNoNum(String opencode) {
        String aa = null;
        opencodeMap = new HashMap<>();
        String[] strings = opencode.split(",");
        List<Integer> list = null;
        for (int i = 0; i < 3; i++) {
            list = new ArrayList<>();
            list.add(Integer.parseInt(strings[i]));
            list.add(Integer.parseInt(strings[i + 1]));
            list.add(Integer.parseInt(strings[i + 2]));
            switch (i) {
                case 0:
                    aa = "前";
                    break;
                case 1:
                    aa = "中";
                    break;
                case 2:
                    aa = "后";
                    break;
            }
            opencodeMap.put(aa, list);
        }
        getSscDuizi();
        getSscShunzi();
        getSscBaozi();
        getSscBanShun();
        this.opencode = opencode;
    }

    //顺子玩法(rule:顺子前)
    public boolean shunzi(String bet) {
        flag = false;
        if (sscShunzi.size() != 0) {
            String bets = bet.substring(2, 3);
            if (sscShunzi.contains(bets)) {
                flag = true;
            }
        }
        return flag;
    }

    //豹子玩法(rule:豹子前)
    public boolean baoZi(String bet) {
        flag = false;
        if (sscBaozi.size() != 0) {
            String bets = bet.substring(2, 3);
            if (sscBaozi.contains(bets)) {
                flag = true;
            }
        }
        return flag;
    }

    //对子玩法(rule:对子前)
    public boolean duizi(String bet) {
        flag = false;
        if (sscDuizi.size() != 0) {
            String bets = bet.substring(2, 3);
            if (sscDuizi.contains(bets)) {
                flag = true;
            }
        }
        return flag;
    }

    //半顺玩法(rule:半顺前)
    public boolean banshun(String bet) {
        flag = false;
        if (sscBanShun.size() != 0) {
            String bets = bet.substring(2, 3);
            if (sscBanShun.contains(bets)) {
                flag = true;
            }
        }
        return flag;
    }

    //杂六玩法(rule:杂六)
    public boolean zaLiu(String bet) {
        flag = false;
        //判断5个数字完全不同
        boolean flg = false ;
        Set<String> set = new HashSet<>();
        String openArray = opencode.replace(",","");
        for(int i = 0 ; i<5;i++){
            try {
                set.add(openArray.substring(i,i+1));
            }catch (Exception e){
            }
        }
        if(set.size() == 5){
            flg=true;
        }
        if (sscBanShun.size() == 0 && sscDuizi.size() == 0 && sscBaozi.size() == 0 && sscShunzi.size() == 0 && flg) {
            flag = true;
        }
        return flag;
    }

    //获取顺子中奖的情况
    public void getSscShunzi() {
        sscShunzi = new ArrayList<>();
        for (Map.Entry<String, List<Integer>> entry : opencodeMap.entrySet()) {
            int[] opencodeToInt = new int[]{
                    entry.getValue().get(0), entry.getValue().get(1), entry.getValue().get(2)
            };
            Arrays.sort(opencodeToInt);
            String special = opencodeToInt[0]+""+opencodeToInt[1]+""+opencodeToInt[2];
            List<String> list = new ArrayList<>();
            list.add("019");
            list.add("089");
            boolean common = (opencodeToInt[1] - opencodeToInt[0] == 1) && (opencodeToInt[2] - opencodeToInt[1] == 1);
            if (common || list.contains(special)) {
                sscShunzi.add(entry.getKey());
            }
        }
    }

    //获取豹子中奖的情况
    public void getSscBaozi() {
        sscBaozi = new ArrayList<>();
        for (Map.Entry<String, List<Integer>> entry : opencodeMap.entrySet()) {
            List<Integer> list = entry.getValue();
            if ((list.get(0) == list.get(1)) && (list.get(0) == list.get(2))) {
                sscBaozi.add(entry.getKey());
            }
        }
    }

    //获取对子中奖的情况
    public void getSscDuizi() {
        sscDuizi = new ArrayList<>();
        for (Map.Entry<String, List<Integer>> entry : opencodeMap.entrySet()) {
            List<Integer> list = entry.getValue();
            Set<Integer> set = new HashSet<>();
            for (Integer string : list) {
                try {
                    set.add(string);
                } catch (Exception e) {
                }
            }
            if (set.size() == 2) {
                sscDuizi.add(entry.getKey());
            }
        }
    }

    //获取半顺的中奖情况
    public void getSscBanShun() {
        sscBanShun = new ArrayList<>();
        for (Map.Entry<String, List<Integer>> entry : opencodeMap.entrySet()) {
            List<Integer> list = entry.getValue();
            //排除顺子的情况
            int[] opencodeToInt = new int[]{
                    list.get(0), list.get(1), list.get(2)
            };
            Arrays.sort(opencodeToInt);
            String special = opencodeToInt[0]+""+opencodeToInt[1]+""+opencodeToInt[2];
            List<String> listzz = new ArrayList<>();
            listzz.add("019");
            listzz.add("089");
            boolean common = (opencodeToInt[1] - opencodeToInt[0] == 1) && (opencodeToInt[2] - opencodeToInt[1] == 1);
            boolean shunzi = (common || listzz.contains(special));
            boolean duizi = sscDuizi.contains(entry.getKey());
            if ((!shunzi)&& (!duizi)) {
                    if (Math.abs(list.get(0) - list.get(1)) == 1 || Math.abs(list.get(1) - list.get(2)) == 1) {
                    sscBanShun.add(entry.getKey());
                }
            }
        }
    }


}
